/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package isi.corba;

import isi.corba.entites.Categorie;
import isi.corba.entites.Client;
import isi.corba.entites.Produit;
import isi.corba.entites.SousCategorie;
import java.sql.SQLException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CosNaming.NamingContextPackage.CannotProceed;
import org.omg.CosNaming.NamingContextPackage.NotFound;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAPackage.ServantNotActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;


/**
 *
 */
public class Main {


    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws SQLException {

        EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("CORBA_PU");
        EntityManager em = emFactory.createEntityManager();
        EntityTransaction transac = em.getTransaction();
        transac.begin();
        Client test=new Client("Dupond", "Andre", "da", "toto");
        Categorie categ=new Categorie();
        categ.setNom("Telephonie");
        categ.setDescription("Tout l'univers de la téléphonie quelle soit mobile ou fixe!");
        SousCategorie sCateg=new SousCategorie();
        sCateg.setCategorie(categ);
        sCateg.setNom("Smartphone");
        sCateg.setDescription("Tout les smartphone HTC, Iphone, Symbian...");

        Produit prod=new Produit();
        prod.setVendeur(test);
        prod.setLibelle("Iphone");
        prod.setDescriptif("Le téléphone à LRS!");
        prod.setDateEcheance(new Date(2011, 03, 20));
        prod.setPrixAchatImmediat(50);
        prod.setPrixDepart(1);
        prod.setSousCategorie(sCateg);
        em.persist(test);
        em.persist(categ);
        em.persist(sCateg);
        em.persist(prod);
        transac.commit();

        try {
            ServerMain.mainserver(args, em);
            em.close();
            emFactory.close();
        } catch (AdapterInactive ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidName ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ServantNotActive ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (WrongPolicy ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (org.omg.CosNaming.NamingContextPackage.InvalidName ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NotFound ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CannotProceed ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
